#!/bin/sh
#			SCF - SwinConFiguration filename
#			SAV- name of Saved file.
#			SYS- name of System wide configuration defaults file.
PATH=/usr/sbin:/usr/bsd:/sbin:/usr/bin:/bin:/usr/bin/X11
export PATH
SCF=$HOME/.swin2config
SAV=$SCF.pre2.00
SYS=$SWIN2HOME/sys.swin2config
HINTS=$SWIN2HOME/swin_hints 
HINTS_HTML=$SWIN2HOME/swin_hints.html
VIEWED=$SWIN2HOME/swin_hints_viewed
FGREP=/usr/bin/fgrep
GREP=/sbin/grep
UNAME=/sbin/uname
XCONFIRM=/usr/bin/X11/xconfirm
CAT=/sbin/cat
CPIO=/sbin/cpio
AWK=/usr/bin/awk
FIND=/sbin/find
SED=/sbin/sed
PS=/sbin/ps
MV=/sbin/mv
SLEEP=/sbin/sleep
NETSCAPE=/usr/bin/X11/netscape
HOSTNAME=`$UNAME -n`
LICENSE_FILE=$SWIN2HOME/FLEXlm/license.dat
LICENSE_FILE_BAK=$SWIN2HOME/FLEXlm/license.bak
HOSTID=`/usr/lib/SoftWindows2/FLEXlm/lmhostid | tail -10c | sed -e 's/"//'`

if [ -r $LICENSE_FILE ]; then
   if $FGREP -s SERVER $LICENSE_FILE; then
      fnam=`grep SERVER $LICENSE_FILE | head -1 | $AWK '{ print $2 }'`
      fid=`grep SERVER $LICENSE_FILE  | head -1 | $AWK '{ print $3 }'`
      if [ $HOSTID = $fid ]; then
         if [ $HOSTNAME != $fnam ]; then
            $MV $LICENSE_FILE $LICENSE_FILE_BAK
            $SED -e "s^$fnam^$HOSTNAME^" $LICENSE_FILE_BAK > $LICENSE_FILE
         fi
      fi
   fi
fi

`ln -sf $SWIN2HOME/local/SGIus $SWIN2HOME/local/selected`
DD=`$FGREP KEYBOARD_MAP_FILE_NAME $SYS | $AWK '{ print $2 }'`
if [ "$DD" = "" ] ;  then
#
# If this is an IP22 then install the US INDY Keyboard
#
if [ "`$UNAME -m`" = "IP22" -o "`$UNAME -m`" = "IP26" ]
then
        # We're on an Indy
	case `$XCONFIRM -c -header "SoftWindows Installation" -icon question -exclusive -B "US" -b "French" -b "German" -b "UK" -t "SoftWindows could not determine your system" -t "default language." -t "" -t "Please choose a default language."` in
		French)
	                LOCALDIR=$SWIN2HOME/local/SGIfr
		;;
		German)
                	LOCALDIR=$SWIN2HOME/local/SGIgr
        	;;
		UK)
                	LOCALDIR=$SWIN2HOME/local/SGIuk
        	;;
		US)
        	        LOCALDIR=$SWIN2HOME/local/SGIus
	        ;;      
	esac
	
	$CAT $SWIN2HOME/sys.swin2config | $SED -f $LOCALDIR/upd_i_keymap > $SWIN2HOME/new.swin2config
	mv $SWIN2HOME/new.swin2config $SWIN2HOME/sys.swin2config
	ln -sf $LOCALDIR $SWIN2HOME/local/selected
else
        case `$XCONFIRM -c -header "SoftWindows Installation" -icon question -exclusive -B "US" -b "French" -b "German" -b "UK" -t "SoftWindows could not determine your system" -t "default language." -t "" -t "Please choose a default language."` in
                French)
                        LOCALDIR=$SWIN2HOME/local/SGIfr
                ;;
                German)
                        LOCALDIR=$SWIN2HOME/local/SGIgr
                ;;
                UK)
                        LOCALDIR=$SWIN2HOME/local/SGIuk
                ;;
                US)
                        LOCALDIR=$SWIN2HOME/local/SGIus
                ;;
        esac

        case `$XCONFIRM -c -header "SoftWindows Installation" -icon question -exclusive -B "Exit" -b "PS/2 Style" -b "Indigo" -t "SoftWindows could not determine your keyboard" -t "type during installation." -t "" -t "Select PS/2 Style if you are running" -t "on an INDY or Indigo2 Workstation" -t "" -t "Select Indigo for all others"` in
                "PS/2 Style")
		        $CAT $SWIN2HOME/sys.swin2config | $SED -f $LOCALDIR/upd_i_keymap > $SWIN2HOME/new.swin2config
		        mv $SWIN2HOME/new.swin2config $SWIN2HOME/sys.swin2config
		;;
		Indigo)
		        $CAT $SWIN2HOME/sys.swin2config | $SED -f $LOCALDIR/upd_keymap > $SWIN2HOME/new.swin2config
		        mv $SWIN2HOME/new.swin2config $SWIN2HOME/sys.swin2config
			ln -sf $LOCALDIR $SWIN2HOME/local/selected
		;;
		Exit)
			exit
		;;
	esac
fi

( cd $LOCALDIR/local ; $FIND . -print | $CPIO -pud $SWIN2HOME/local ) 2> /dev/null

fi

if [ -f $SCF ] ; then
	if [ -r $SCF ] ; then
		if  $FGREP -s WINDOW_RESIZE_MODE $SCF ; then echo 1 >/dev/null
		else
			if  mv $SCF $SAV ; then
				DD=`$FGREP DRIVE_C_FILE_NAME $SAV | $AWK '{ print $2 }'`
				if [ "$DD" = "" ] ;  then
					DD=`$FGREP DRIVE_C_FILE_NAME $SYS | $AWK '{ print $2 }'`
				fi
				if [ "$DD" = "" ] ; then
					DD=$SWIN2HOME/MS-WIN-311.hdf
				fi
				$SED -e "s^DRIVE_C_FILE.*^DRIVE_C_FILE_NAME^" \
					-e "s^DRIVE_D_FILE.*^DRIVE_D_FILE_NAME     $DD^" $SAV >$SCF
				if $FGREP WINDOW_RESIZE_MODE $SYS >>$SCF ; then echo 1 >/dev/null
				else
					echo "WINDOW_RESIZE_MODE                restart_win" >>$SCF
				fi
			else
				echo "rename of $SCF to $SAV failed"
				exit 2;
			fi
		fi
	else
		echo "$SCF exists but cannot be read."
		exit 1;
	fi
fi

exit 0;
